<template>
	<u-popup v-model="isShow" mode="center" width="590" height="812" :isScroll="false">
		<view class="official-follow-main">
			<view class="official-follow-title">
				关注小律懂法公众号
			</view>
			<view class="official-follow-subtitle">
				案件进度早知道
			</view>
			<view class="official-follow-qrcode" @longpress="onLongpress">
				<image style="width: 100%;height:100%;" show-menu-by-longpress :src="qrCode"/>
			</view>
			<view class="official-follow-tips">
				长按识别二维码
			</view>
			<button class="confirm-btn" :disabled="disabled||!isLongpress" :class="{'disabled':disabled||!isLongpress}" @click="confirm">已识别二维码关注</button>
		</view>
	</u-popup>
</template>

<script>
	export default {
		options: {
			styleIsolation: 'shared'
		},
		data() {
			return {
				isShow: false,
				qrCode:'',
				followStatus:null,
				followSuccess:null,
				disabled:true,
				isLongpress:false,
			}
		},
		async created() {
			this.followStatus = new Promise((resolve, reject) => {
				this.followSuccess = resolve;
			});
			const {data} = await this.$u.post(this.$restUrl.getOfficialFollowQRCode);
			this.qrCode = data.qrcode_url;
		},
		mounted(){
			uni.$off('followed');
			uni.$on('followed',()=>{
				this.onFollowed();
			})
		},
		methods:{
			 checkFollow(){
				return new Promise(async (resolve)=>{
					this.$u.post(this.$restUrl.checkUserOfficialFollowStatus).then(res=>{
						this.isShow = false;
						resolve();
					}).catch(async err=>{
						this.isShow = true;
						await this.followStatus;
						resolve();
					})
					
					
					// const {status_code} = await this.$u.post(this.$restUrl.checkUserOfficialFollowStatus);
					// console.log(status_code)
					// if(status_code == 404){
					// 	console.log('11111111111111111111111111111')
					// 	this.isShow = true;
					// 	await this.followStatus;
					// 	resolve();
					// }else{
					// 	this.isShow = false;
					// 	resolve();
					// }
				})
			},
			onFollowed(){
				this.disabled = !this.isShow;
			},
			async confirm(){
				this.$u.post(this.$restUrl.putUserConfirmFollow);
				this.isShow = false;
				this.followSuccess();
			},
			onLongpress(){
				this.isLongpress = true;
			}
		}
	}
</script>

<style scoped lang="scss">
	/deep/ .u-mode-center-box{
		background-color: transparent !important;
		background: url(https://vkceyugu.cdn.bspapp.com/VKCEYUGU-8acfaa58-aeb5-4502-8309-365d4c6cca4a/70402408-ea8a-4fa4-a5e6-85aa696d3354.png) no-repeat;
		background-size: 100% 100%;
	}
	/deep/ .uni-scroll-view{
		overflow: initial !important;
	}
	/deep/ .u-drawer__scroll-view{
		height: 130% !important;
	}
	.official-follow-main{
		margin-top: 280rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		.official-follow-title{
			height: 72rpx;
			font-size: 40rpx;
			font-family: $global-font-family;
			font-weight: 800;
			color: #1D1D1F;
			line-height: 72rpx;
		}
		.official-follow-subtitle{
			height: 56rpx;
			font-size: 36rpx;
			font-family: $global-font-family;
			// font-weight: 800;
			color: #1D1D1F;
			line-height: 56rpx;
		}
		.official-follow-qrcode{
			width: 156rpx;
			height: 156rpx;
			margin-top: 32rpx;
		}
		.official-follow-tips{
			height: 40rpx;
			font-size: 28rpx;
			font-family: $global-font-family;
			font-weight: 400;
			color: #333333;
			line-height: 40rpx;
		}
		.confirm-btn{
			width: 452rpx;
			height: 88rpx;
			background: #188CF1;
			border-radius:24rpx;
			font-size: 32rpx;
			font-family: $global-font-family;
			font-weight: 400;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 32rpx;
			&::after{
				border: none;
			}
			&.disabled{
				background-color: #9acafc !important;
			}
		}
	}
</style>
